#include "../game_server.cpp"
#include "../room.cpp"
#include "../user.cpp"
#include "../protocol_dist.hpp"
#include "ws_websocket.hpp"
#include <iostream>

using namespace std;
using namespace winux;
FASTDO_API void ActionMain(ProtocolC2SLoginUser *msg, pWsReqCtx ctx, GameServer &game)
{
    ProtocolS2CLoginUser rtn;

    for (auto &user : game.userList)
    {
        if (user->token == msg->token)
        {
            if (!user->isLogged)
            {
                user->login(ctx);
            }
            rtn.user->sessionTime = user->sessionTime;
            rtn.user->token = user->token;
            rtn.ok = true;
        }
        else
        {
            cout << endl;
        }
    }
    ctx->send(ws::OpCode::dataText, false, rtn.toMixed().json());
}